<?php
namespace BP\Sys\XML;
require_once("java/util/ArrayList.php");
require_once("BP/DA/Cash.php");
require_once("BP/DA/Depositary.php");
require_once("BP/En/Row.php");
abstract class XmlEn {
	protected $_row;	// Row
	private function __init() { // default class members
		$this->_row = NULL;
	}
	public function getRow () 
	{
		if (($this->_row == NULL))
		{
			$this->_row = new Row();
		}
		return $this->_row;
	}
	public function setRow ($value) // [Row value]
	{
		$this->_row = $value;
	}
	public function GetValByKey ($attrKey) // [String attrKey]
	{
		if (($this->_row == NULL))
		{
			return NULL;
		}
		return $this->getRow()->GetValByKey($attrKey);
	}
	public function GetValIntByKey ($key) // [String key]
	{
		try 
		{
			return $Integer->parseInt($this->GetValByKey($key)->trim());
		}
		catch (\Exception $e)
		{
			throw new \RuntimeException(((("key=" . $key) . "不能向int 类型转换。val=") . $this->GetValByKey($key)));
		}
	}
	public function GetValDecimalByKey ($key) // [String key]
	{
		return $this->GetValByKey($key);
	}
	public function GetValStringByKey ($attrKey) // [String attrKey]
	{
		if (($this->_row == NULL))
		{
			return "";
		}
		try 
		{
			$tempVar = $this->getRow()->GetValByKey($attrKey);
			return (( (($tempVar instanceof String)) ? $tempVar : NULL ));
		}
		catch (\RuntimeException $ex)
		{
			throw new \RuntimeException((((((((" @XMLEN Error Attr=[" . $attrKey) . "], ClassName= ") . $this) . " , File =") . $this->getGetNewEntities()->getFile()) . " , Error = ") . $ex->getMessage()));
		}
	}
	public function GetValStringHtmlByKey ($attrKey) // [String attrKey]
	{
		return $this->GetValStringByKey($attrKey)->replace("\n", "<BR>")->replace(" ", "&nbsp;");
	}
	public function GetValBoolByKey ($key) // [String key]
	{
		$val = $this->GetValStringByKey($key);
		if (($val . NULL))
		{
			if (($val->equals("1") || $val->toUpperCase()->equals("TRUE")))
			{
				return  TRUE ;
			}
			else
			{
				return  FALSE ;
			}
		}
		else
		{
			return  FALSE ;
		}
	}
	public function SetVal ($k, $val) // [String k, Object val]
	{
		$this->getRow()->SetValByKey($k, $val);
	}
	public static function constructor__ () 
	{
		$me = new self();
		$me->__init();
		return $me;
	}
	public static function convertXmlEns ($obj) // [Object obj]
	{
		return $obj;
	}
	public function RetrieveBy_del ($key, $val) // [String key, String val]
	{
		$ens = $this->getGetNewEntities();
		$ens->RetrieveAll();
			/* match: String_Object */
		$ens->RetrieveBy_String_Object($key, $val);
		if (($ens->size() == 0))
		{
			return 0;
		}
			/* match: I */
		$this->setRow($ens->getItem_I(0)->_row);
		return $ens->size();
	}
	public function RetrieveByPK ($key, $val) // [String key, String val]
	{
		$tempVar = $Cash->GetObj($this->getGetNewEntities(), $Depositary->Application);
		$ens = (( (($tempVar instanceof XmlEns)) ? $tempVar : NULL ));
		if (($ens == NULL))
		{
			$ens = $this->getGetNewEntities();
			$ens->RetrieveAll();
		}
		$i = 0;
		foreach (XmlEn::convertXmlEns($ens) as $en) 		{
			if ($en->GetValStringByKey($key)->equals($val))
			{
				$this->setRow($en->getRow());
				++$i;
			}
		}
		if (($i == 1))
		{
			return 1;
		}
		if (($i > 1))
		{
			throw new \RuntimeException((((("@XML = " . $this) . " �? PK=") . $val) . "不唯�?。�?��?��??"));
		}
		return 0;
	}
	public function Retrieve ($key, $val, $key1, $val1) // [String key, String val, String key1, String val1]
	{
		$tempVar = $Cash->GetObj($this->getGetNewEntities(), $Depositary->Application);
		$ens = (( (($tempVar instanceof XmlEns)) ? $tempVar : NULL ));
		if (($ens == NULL))
		{
			$ens = $this->getGetNewEntities();
			$ens->RetrieveAll();
		}
		$i = 0;
		foreach (XmlEn::convertXmlEns($ens) as $en) 		{
			if (($en->GetValStringByKey($key)->equals($val) && $en->GetValStringByKey($key1)->equals($val1)))
			{
				$this->setRow($en->getRow());
				++$i;
			}
		}
		if (($i == 1))
		{
			return 1;
		}
		return 0;
	}
	abstract function getGetNewEntities (); 
	public function toString () 
	{
		return $this->getClass()->getName();
	}
}
?>
